package com.pdsu.xpf.graduation01.control;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.pdsu.xpf.graduation01.service.impl.OrderServiceImpl;
import com.pdsu.xpf.graduation01.utils.Result;
import com.pdsu.xpf.graduation01.vo.OrderVO;
import com.pdsu.xpf.graduation01.vo.UserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@CrossOrigin
@Controller
@RequestMapping("/order_b")
public class BackOrderControl {

    final
    OrderServiceImpl orderService;

    public BackOrderControl(OrderServiceImpl orderService) {
        this.orderService = orderService;
    }

    @ResponseBody
    @RequestMapping("/findAllOrder")
    public Result findAllUser() throws JsonProcessingException {
        List<OrderVO> orderVOS = orderService.findAllOrderVO();
        return Result.success(orderVOS);
    }
    @ResponseBody
    @RequestMapping("/delOrderByOID")
    public Result delOrderByOID(int oid) throws JsonProcessingException {
        int i =orderService.delOrderByOID(oid);
        return Result.success();
    }
    @ResponseBody
    @RequestMapping("/searchOrderByKey")
    public Result searchOrderByKey(String key) throws JsonProcessingException {
        List<OrderVO> orderVOS = orderService.searchOrderByKey("%"+key+"%");
        return Result.success(orderVOS);
    }


}
